//
//  MsgDataCenter.m
//  Safflower
//
//  Created by 袁亮 on 2016/12/19.
//  Copyright © 2016年 Migic_Z. All rights reserved.
//

#import "MsgDataCenter.h"
#import "FriendModel.h"

@implementation MsgDataCenter

- (void)fetchMsgFriendListDataComplation:(void (^)(id, NSString *))complation
{
    UserModel *user = [UserManager fetchUserInfo];
    NSDictionary *param = @{
                            @"user":[NSNumber numberWithInteger:user.userId],
                            };
    
    [HttpRequest POSTRequest:FriendInviteList WithParams:param WithSuccess:^(id responseOjbect) {
        
        if ([[responseOjbect objectForKey:@"code"] integerValue] == 1) {
            NSArray *dataArray = (NSArray *)[responseOjbect objectForKey:@"data"];
            
            NSArray *modelArray = [NSArray yy_modelArrayWithClass:[FriendModel class] json:dataArray];
            
            complation(modelArray,nil);
            
        }else{
            complation(nil,[responseOjbect objectForKey:@"message"]);
        }
        
    } WithFail:^(NSError *error) {
        complation(nil,@"服务器异常");
    }];
}

- (void)becomeFriend:(FriendModel *)friendModel complation:(void (^)(id, NSString *))complation
{
    FriendModel *model = (FriendModel *)friendModel;
    NSDictionary *param = @{
                            @"inviteId":[NSNumber numberWithInteger:model.frdId],
                            };
    
    [HttpRequest POSTRequest:AgreeFriend WithParams:param WithSuccess:^(id responseOjbect) {

        if ([[responseOjbect objectForKey:@"code"] integerValue] == 1) {
            complation([responseOjbect objectForKey:@"message"],nil);
        }else{
            complation(nil,[responseOjbect objectForKey:@"message"]);
        }
        
    } WithFail:^(NSError *error) {
        complation(nil,@"服务器异常");
    }];
}

@end
